home *** CD-ROM | disk | FTP | other *** search
Wrap
/* | file name - dsp_mgr.c |=================================================================== | | This example is a DV-Draw display manager. The screen is | divided into 2 areas. One is used for the display menu, | the other is for displaying DV-Draw applications. The areas | can be defined by a DV-Draw layout file. | | The menu area should contain objects that are "named" the | view file to be "played" in the display area. | | The display views can be a simple DV-Draw view or one with | RULES. | | The example also traverses the menu view and saves all the | referenced demos in a list. If the user selects an object | named "loop", the display manager starts looping through | its list. Each display is active for a period of time. To | break the loop, users can just select another display. | The default number of views you can "loop" between is 50. | The default display time is 15 seconds. | | To quit the display manager, the user can "quit" the window | or select an object named "quit" from the display menu. | | You can overwrite the default state by using the following | arguments: | argv[1] - device (default is DVDEVICE) | argv[2] - menu (default is dsp_menu.v) | argv[3] - initial display (default is dsp_mgr.v) | argv[4] - layout view (default is dsp_mgr.lay) |=================================================================== */ #ifdef WINNT #include <windows.h> #endif #include "std.h" #include "dvstd.h" #include "dvtools.h" #include "dvinteract.h" #include "dvGR.h" #include "GRfundecl.h" #include "Tfundecl.h" #include "VOfundecl.h" #include "VUfundecl.h" #include "VUerfundecl.h" #include "MISCfuns.h" #include "dsp_mgr.h" /* Variables and Constants */ #include "dsp_timer.h" /* Code for timing the "loop" */ #ifndef WINNT /* Include the X based files so we can add AppTimeOuts */ #ifdef CONST #undef CONST #endif #ifndef __STDC__ #define _NO_PROTO #endif /* * X11 include files */ #include <X11/Xlib.h> #include <X11/Intrinsic.h> LOCAL XtAppContext app_context; LOCAL unsigned int TimeoutInterval = 25; LOCAL VOID time_out_proc V_P_((ADDRESS args, XtIntervalId *interval_id)); #endif CHAR *VIstrclone V_P_((CHAR *)); /* Internal funciton: allocates and clones strings */ #define DEF_PATH (CHAR*)NULL #define DEF_DISPFORMS (CHAR*)NULL #define DEF_COLORTABLE (CHAR*)NULL #ifdef WINNT CHAR dsp_message[1024]; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) #else int main (argc, argv) INT argc; CHAR *argv[]; #endif { /* argv[1] - display device (default is defined by DVDEVICE) */ /* argv[2] - menu (default is defined in dsp_mgr.h) */ /* argv[3] - initial display (default is defined in dsp_mgr.h) */ /* argv[4] - layout view (default is defined in dsp_mgr.h) */ CHAR *device = NULL; DV_BOOL done = NO; CHAR *menu_view_name, *display_view_name, *layout_view_name; OBJECT location; #ifdef WINNT INT argc; CHAR **argv; /* Initialize the arguments */ make_argv(&argc,&argv,lpCmdLine); #endif /* Initialize DV-Tools using the default DVconfig path */ (VOID) TInit (DEF_PATH, DEF_DISPFORMS); /* Initialize the screen */ device = (argc > 1) ? argv[1] : NULL; ScreenInit (argv[0], device); /* Initialize the Display Areas */ menu_view_name = (argc > 2) ? argv[2] : MenuViewName; display_view_name = (argc > 3) ? argv[3] : DisplayViewName; layout_view_name = (argc > 4) ? argv[4] : LayoutViewName; DisplayInit (menu_view_name, display_view_name, layout_view_name); #ifndef WINNT /* Get the Xt based information */ GRget (V_X_APPLIC_CONTEXT, &app_context, V_END_OF_LIST); /* Post a timeout for dynamic updates | The timeout procedure will update the dynamics of | all screens which have been opened. The procedure is invoked | whenever the specified time interval elapses. The interval is | specified in milliseconds. */ XtAppAddTimeOut (app_context, TimeoutInterval, (XtTimerCallbackProc)time_out_proc, NULL); #endif /* Go into a loop, handling user updates and updating displays */ while (!done) { #ifdef WINNT /* Update the Display */ HandleUpdates(); /* Get the Event */ location = VOloWinEventPoll( V_NO_WAIT ); #else /* See if there is an event to handle, only user input events | matching those set in VOscWinEventMask will be returned. | | NOTE: VOloWinEventPoll will get the next event and then dispatch | non-DataViews events. Our posted AppTimeOut event to handle | dynamics, will be called as needeb by VOloWinEventPoll, which | calls XtAppNextEvent and XtDispatchEvent. */ location = VOloWinEventPoll( V_WAIT ); #endif /* Handle Event */ if( location ) HandleEvents( location, &done ); } /* Cleanup */ DisplayCleanup (); (VOID) TTerminate (); return EXIT_OK; } #ifndef WINNT LOCAL VOID time_out_proc (args, interval_id) ADDRESS args; XtIntervalId *interval_id; { /* Handle Updates */ HandleUpdates(); XtAppAddTimeOut (app_context, TimeoutInterval, (XtTimerCallbackProc)time_out_proc, NULL); } #endif LOCAL void HandleUpdates() { /* If we are looping, switch demos */ if( DemoLooping && TimedOut() ) SwitchDemo(); /* If we are displaying a demo, update it */ if( Proto_Env ) TprotoUpdate( Proto_Env ); } /*------------------------------------------------------------------------*/ LOCAL void ScreenInit (program_name, device) CHAR *program_name, *device; { int error_code=0; char buf[50]; /* Open the screen using DVDEVICE and the default color table. | Also, name the window, and offset it from the upper left corner. */ VUoff_copyright(); DVscreen = TscOpenSet( device, DEF_COLORTABLE, V_WINDOW_NAME, "DataViews Feature Demo", V_ACTIVE_CURSOR, #ifdef WINNT #ifdef DOUBLE_BUFFER V_WIN32_DOUBLE_BUFFER, YES, #endif #else V_X_EXPOSURE_BLOCK, YES, #endif V_END_OF_LIST); /* If we couldn't open a device, exit the program */ if (!DVscreen) { error_code=TscOpenError(); #ifdef WINNT if((error_code>=6)&&(error_code<=9)) { sprintf(buf,"Product is not validated. Error code %d.",error_code); MessageBox(NULL,buf,"Validation Error",MB_OK); } else { (VOID)sprintf( dsp_message,"\nDataViews environment variable DVDEVICE must be defined.\n or\nUsage: %s <device>\n", program_name); MessageBox ( GetFocus (), dsp_message, "Display Manager", MB_ICONSTOP ); } #else if((error_code>=6)&&(error_code<=9)) fprintf(stderr,"Product is not validated. Error code %d.",error_code); else { (VOID) printf ("\nDataViews environment variable DVDEVICE must be defined.\n"); (VOID) printf (" or\n"); (VOID) printf ("Usage: %s <device>\n", program_name); } #endif exit (EXIT_ERR); } /* Erase the copyright message */ (VOID) TscErase (DVscreen); /* Define the types of user inputs to gather */ (VOID) VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE | V_BUTTONPRESS | V_BUTTONRELEASE | V_MOTIONNOTIFY | V_ENTERNOTIFY | V_LEAVENOTIFY | V_EXPOSE | V_RESIZE | V_WINDOW_QUIT, 0L); } /*------------------------------------------------------------------------*/ LOCAL void DisplayInit (menu_name, display_name, layout_name) CHAR *menu_name, *display_name, *layout_name; { VIEW view; RECTANGLE wvp, box, dummy; INT i; /* Get the display areas from the layout file */ view = TviLoad (layout_name); if (view) { for (i = 0; i < NUM_DISPLAY_AREAS; i++) { /* Get the area to be used by the drawport */ VOobBox (TdrGetNamedObject (TviGetDrawing (view), AreaName[i]), &box, &dummy); /* Since the "world coordinates" are -16K to 16K and the | "virtual screen coordinates" are 0K to 32K we can | just add 16K to the "world" to translate it to "virtual" */ DpArea[i].ll.x = box.ll.x + XMAX; DpArea[i].ll.y = box.ll.y + YMAX; DpArea[i].ur.x = box.ur.x + XMAX; DpArea[i].ur.y = box.ur.y + YMAX; } (VOID) TviDestroy (view); } else #ifdef WINNT { (VOID) sprintf (dsp_message,"Using the default layout.\n"); MessageBox (GetFocus (), dsp_message, "Display Manager", MB_OK); } #else (VOID) printf ("Using the default layout.\n"); #endif /* Load the menu view. Make it stretch into the menu area. */ view = TviLoad (menu_name); if (!view) #ifdef WINNT { (VOID)sprintf(dsp_message,"You must specify a menu V_view file or\n the default V_view must be available.\nDisplay Manager arguments will override defaults:\n (menu name) (initial display name) (layout name)\nDefaults: \n \"%s\" \"%s\" \"%s\"\n",MenuViewName, DisplayViewName, LayoutViewName); MessageBox ( GetFocus (), dsp_message, "Display Manager", MB_ICONSTOP ); exit( EXIT_ERR ); } #else { (VOID) printf ("You must specify a menu view file or\n"); (VOID) printf (" the default view, %s, must be available.\n", MenuViewName); (VOID) printf ("Display Manager arguments will override defaults:\n"); (VOID) printf (" (menu name) (initial display name) (layout name)\n"); (VOID) printf ("Defaults: \n"); (VOID) printf (" \"%s\" \"%s\" \"%s\"\n", MenuViewName, DisplayViewName, LayoutViewName); exit (EXIT_ERR); } #endif VOobBox (TviGetDrawing (view), &wvp, &dummy); MenuDp = TdpCreateStretch (DVscreen, view, &DpArea[MENU], &wvp); MenuDsl = TviGetDataSourceList (view); (VOID) TdlOpenData (MenuDsl); /* For "looping", create a list of views referenced by the display menu */ DemoCount = 0; (VOID) TdrForEachNamedObject (TviGetDrawing (view), (TDRFOREACHNAMEDOBJFUNPTR) GetDemoNames, (ADDRESS) & DemoCount); /* Load the initial display view.*/ view = TviLoad (display_name); if (!view) view = TviCreate (); DisplayDp = TdpCreate (DVscreen, view, &DpArea[DISPLAY], (RECTANGLE *) NULL); /* Draw both drawports */ (VOID) TdpDraw (MenuDp); (VOID) TdpDraw (DisplayDp); } /*------------------------------------------------------------------------*/ LOCAL void RedrawDisplay () { /* Redraw the display areas, this is called after a RESIZE or EXPOSE */ (VOID) TdpRedraw (MenuDp, (RECTANGLE *) NULL, YES); if (Proto_Env) (VOID) TprotoRedraw (Proto_Env); else (VOID) TdpRedraw (DisplayDp, (RECTANGLE *) NULL, YES); } /*------------------------------------------------------------------------*/ LOCAL void HandleEvents (location, done) OBJECT location; DV_BOOL *done; { DRAWPORT selected_dp; INT proto_status; INT key_test; /* Process the user input, Some systems generate a EXPOSE | event after a resize, some don't. We'll keep track of | resize events so we won't end up drawing the display | twice. */ switch (VOloType (location)) { case V_KEYPRESS: key_test = VOloKeySym(location); RedrawDisplay(); break; case V_EXPOSE: RedrawDisplay (); break; case V_RESIZE: (VOID) TscReset (DVscreen); break; case V_WINDOW_QUIT: *done = YES; break; default: selected_dp = TloGetSelectedDrawport (location); /* If we pick inside the Menu Area... */ if (selected_dp == MenuDp) *done = HandleMenu (location); /* Else if a demo is running pass the event to the Proto Handler */ else if (Proto_Env) { proto_status = TprotoHandleInput (Proto_Env, location); if (proto_status == V_TPROTO_QUIT) { TprotoCleanup (Proto_Env); Proto_Env = NULL; (VOID) TdpDraw (DisplayDp); } } break; } } /*------------------------------------------------------------------------*/ LOCAL BOOLPARAM HandleMenu (location) OBJECT location; { CHAR *obj_name; /* See if we "picked" not just moved the cursor */ if (VOloType (location) == V_KEYPRESS || VOloType (location) == V_BUTTONPRESS) { /* Get the name of the object... | if "quit", return YES else return NO. | else if "loop", set the DemoLoop flag. | else get the object name and make it the next demo. */ obj_name = TloGetSelectedObjectName (location); if (obj_name) { if (strcmp (obj_name, "quit") == 0) return YES; else if (strcmp (obj_name, "loop") == 0) { DemoLooping = YES; DemoIndex = -1; } #ifndef WINNT else if (strcmp (obj_name, "faster") == 0) TimeoutInterval = 0; else if (strcmp (obj_name, "slower") == 0) TimeoutInterval = 25; #endif else { /* Make this the new prototype */ DemoLooping = NO; InitDemo (obj_name); } } } return NO; } /*------------------------------------------------------------------------*/ LOCAL void InitDemo (view_name) CHAR *view_name; { DRAWPORT_ATTRIBUTES dp_atts; /* Setup the display attributes */ dp_atts.vvp = &DpArea[DISPLAY]; dp_atts.wvp = NULL; dp_atts.stretch_flag = (DV_BOOL) NO; /* Clean up the old display, before drawing the new one */ if (Proto_Env) TprotoCleanup (Proto_Env); /* Set Proto_Env to NULL, so if a timeoutproc gets called during | TprotoInt... we don't have an invalid proto_env. */ Proto_Env = 0; /* Initialize the new demo display */ Proto_Env = TprotoInit (DVscreen, view_name, &dp_atts); /* If the display wasn't loaded, display the default view */ if (!Proto_Env) (VOID) TdpDraw (DisplayDp); } /*------------------------------------------------------------------------*/ /* ARGSUSED */ LOCAL ADDRESS GetDemoNames (obj, name, num_displays) OBJECT obj; CHAR *name; INT *num_displays; { /* Don't include the "loop" and "quit" named objects */ if (S_STRCMP ("ArrowPath", name) == 0 || S_STRCMP ("loop", name) == 0 || S_STRCMP ("quit", name) == 0) return (ADDRESS) NULL; /* Save this display name */ DemoName[*num_displays] = VIstrclone (name); *num_displays = *num_displays + 1; /* Don't go beyond the max number of displays */ if (*num_displays == MAX_DEMOS) return (ADDRESS) - 1; else return (ADDRESS) NULL; } /*------------------------------------------------------------------------*/ LOCAL void SwitchDemo () { /* Get the next demo to display */ DemoIndex++; DemoIndex = (DemoIndex >= DemoCount) ? 0 : DemoIndex; /* Display the new demo */ InitDemo (DemoName[DemoIndex]); /* Reset the loop timer */ InitTimer (); } /*------------------------------------------------------------------------*/ LOCAL void DisplayCleanup () { VIEW view; /* Clean up the menu area */ view = TdpGetView (MenuDp); (VOID) TdpDestroy (MenuDp); (VOID) TviDestroy (view); /* Clean up the default display area */ view = TdpGetView (DisplayDp); (VOID) TdpDestroy (DisplayDp); (VOID) TviDestroy (view); /* Clean up the current demo */ if (Proto_Env) TprotoCleanup (Proto_Env); /* Close the screen */ (VOID) TscClose (DVscreen); }